//
//  UIViewController+LifeCycle.m
//  TKLobby
//
//  Created by yao zhaofeng on 2022/8/11.
//  Copyright © 2022 JJMatch. All rights reserved.
//

#import "UIViewController+LifeCycle.h"
#import <objc/runtime.h>
#import "NSObject+Swizzling.h"

@implementation UIViewController (LifeCycle)
+ (void)load {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        Class class = object_getClass(self);
        SEL originalSelector = @selector(viewDidAppear:);
        SEL swizzleSelector = @selector(jj_viewDidAppear:);
//        [self swizzleSelector:originalSelector withSelector:swizzleSelector];
        Method originalMethod = class_getInstanceMethod(class, originalSelector);
        Method swizzleMethod = class_getInstanceMethod(class, swizzleSelector);
        method_exchangeImplementations(originalMethod, swizzleMethod);
        
        
        originalSelector = @selector(viewWillAppear:);
        swizzleSelector = @selector(jj_viewWillAppear:);
//        [self swizzleSelector:originalSelector withSelector:swizzleSelector];
        originalMethod = class_getInstanceMethod(class, originalSelector);
        swizzleMethod = class_getInstanceMethod(class, swizzleSelector);
        method_exchangeImplementations(originalMethod, swizzleMethod);
        
        
        originalSelector = @selector(viewWillDisappear:);
        swizzleSelector = @selector(jj_viewWillDisappear:);
//        [self swizzleSelector:originalSelector withSelector:swizzleSelector];
        originalMethod = class_getInstanceMethod(class, originalSelector);
        swizzleMethod = class_getInstanceMethod(class, swizzleSelector);
        method_exchangeImplementations(originalMethod, swizzleMethod);
        
        
        originalSelector = @selector(viewDidDisappear:);
        swizzleSelector = @selector(jj_viewDidDisappear:);
        [self swizzleSelector:originalSelector withSelector:swizzleSelector];
//        originalMethod = class_getInstanceMethod(class, originalSelector);
//        swizzleMethod = class_getInstanceMethod(class, swizzleSelector);
//        method_exchangeImplementations(originalMethod, swizzleMethod);
    });
}

- (void)jj_viewWillAppear:(BOOL)animated {
    [self jj_viewWillAppear:animated];
    
}

- (void)jj_viewDidAppear:(BOOL)animated {
    [self jj_viewDidAppear:animated];
    
}


- (void)jj_viewWillDisappear:(BOOL)animated {
    [self jj_viewDidAppear:animated];
    
}


- (void)jj_viewDidDisappear:(BOOL)animated {
    [self jj_viewDidAppear:animated];
    
}

@end
